from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-20 14:06:25.165181
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 20, Feb, 2021
Time: 14:06:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3134
Nobs: 208.000 HQIC: -47.1736
Log likelihood: 2400.53 FPE: 1.81747e-21
AIC: -47.7575 Det(Omega_mle): 1.19105e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.463743 0.138311 3.353 0.001
L1.Burgenland 0.077314 0.070802 1.092 0.275
L1.Kärnten -0.217912 0.059944 -3.635 0.000
L1.Niederösterreich 0.134027 0.164260 0.816 0.415
L1.Oberösterreich 0.244964 0.143953 1.702 0.089
L1.Salzburg 0.209112 0.076252 2.742 0.006
L1.Steiermark 0.098381 0.103067 0.955 0.340
L1.Tirol 0.140718 0.068885 2.043 0.041
L1.Vorarlberg -0.011393 0.062856 -0.181 0.856
L1.Wien -0.124354 0.134945 -0.922 0.357
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.475498 0.167319 2.842 0.004
L1.Burgenland 0.014721 0.085651 0.172 0.864
L1.Kärnten 0.354936 0.072516 4.895 0.000
L1.Niederösterreich 0.114918 0.198710 0.578 0.563
L1.Oberösterreich -0.140561 0.174144 -0.807 0.420
L1.Salzburg 0.194881 0.092244 2.113 0.035
L1.Steiermark 0.207897 0.124684 1.667 0.095
L1.Tirol 0.142077 0.083332 1.705 0.088
L1.Vorarlberg 0.161099 0.076038 2.119 0.034
L1.Wien -0.512667 0.163247 -3.140 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.317189 0.062229 5.097 0.000
L1.Burgenland 0.103826 0.031855 3.259 0.001
L1.Kärnten -0.017480 0.026970 -0.648 0.517
L1.Niederösterreich 0.086233 0.073903 1.167 0.243
L1.Oberösterreich 0.298030 0.064767 4.602 0.000
L1.Salzburg -0.002863 0.034307 -0.083 0.933
L1.Steiermark -0.017519 0.046372 -0.378 0.706
L1.Tirol 0.086148 0.030992 2.780 0.005
L1.Vorarlberg 0.106896 0.028280 3.780 0.000
L1.Wien 0.045935 0.060714 0.757 0.449
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222705 0.069860 3.188 0.001
L1.Burgenland -0.005821 0.035762 -0.163 0.871
L1.Kärnten 0.020510 0.030278 0.677 0.498
L1.Niederösterreich 0.033343 0.082967 0.402 0.688
L1.Oberösterreich 0.383848 0.072710 5.279 0.000
L1.Salzburg 0.087660 0.038514 2.276 0.023
L1.Steiermark 0.181613 0.052059 3.489 0.000
L1.Tirol 0.039736 0.034793 1.142 0.253
L1.Vorarlberg 0.087945 0.031748 2.770 0.006
L1.Wien -0.052656 0.068160 -0.773 0.440
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.517350 0.138614 3.732 0.000
L1.Burgenland 0.060560 0.070957 0.853 0.393
L1.Kärnten 0.017619 0.060076 0.293 0.769
L1.Niederösterreich -0.021005 0.164620 -0.128 0.898
L1.Oberösterreich 0.133385 0.144268 0.925 0.355
L1.Salzburg 0.059103 0.076419 0.773 0.439
L1.Steiermark 0.126692 0.103293 1.227 0.220
L1.Tirol 0.211577 0.069035 3.065 0.002
L1.Vorarlberg 0.026831 0.062993 0.426 0.670
L1.Wien -0.122859 0.135240 -0.908 0.364
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167011 0.097734 1.709 0.087
L1.Burgenland -0.013547 0.050031 -0.271 0.787
L1.Kärnten -0.009900 0.042358 -0.234 0.815
L1.Niederösterreich 0.108084 0.116071 0.931 0.352
L1.Oberösterreich 0.385220 0.101721 3.787 0.000
L1.Salzburg -0.019958 0.053882 -0.370 0.711
L1.Steiermark -0.021560 0.072830 -0.296 0.767
L1.Tirol 0.185498 0.048676 3.811 0.000
L1.Vorarlberg 0.044519 0.044416 1.002 0.316
L1.Wien 0.182194 0.095356 1.911 0.056
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.230417 0.126148 1.827 0.068
L1.Burgenland 0.057719 0.064576 0.894 0.371
L1.Kärnten -0.039838 0.054673 -0.729 0.466
L1.Niederösterreich -0.030136 0.149816 -0.201 0.841
L1.Oberösterreich -0.088899 0.131294 -0.677 0.498
L1.Salzburg 0.045253 0.069547 0.651 0.515
L1.Steiermark 0.388499 0.094004 4.133 0.000
L1.Tirol 0.482402 0.062827 7.678 0.000
L1.Vorarlberg 0.163531 0.057328 2.853 0.004
L1.Wien -0.207299 0.123078 -1.684 0.092
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080130 0.152259 0.526 0.599
L1.Burgenland 0.032797 0.077942 0.421 0.674
L1.Kärnten -0.077073 0.065990 -1.168 0.243
L1.Niederösterreich 0.269043 0.180825 1.488 0.137
L1.Oberösterreich -0.035632 0.158470 -0.225 0.822
L1.Salzburg 0.244787 0.083942 2.916 0.004
L1.Steiermark 0.137217 0.113461 1.209 0.227
L1.Tirol 0.059074 0.075831 0.779 0.436
L1.Vorarlberg 0.057731 0.069195 0.834 0.404
L1.Wien 0.235928 0.148554 1.588 0.112
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.586555 0.082583 7.103 0.000
L1.Burgenland -0.038827 0.042275 -0.918 0.358
L1.Kärnten -0.012075 0.035792 -0.337 0.736
L1.Niederösterreich -0.015818 0.098077 -0.161 0.872
L1.Oberösterreich 0.304690 0.085952 3.545 0.000
L1.Salzburg 0.017428 0.045529 0.383 0.702
L1.Steiermark 0.003517 0.061540 0.057 0.954
L1.Tirol 0.078667 0.041130 1.913 0.056
L1.Vorarlberg 0.120197 0.037530 3.203 0.001
L1.Wien -0.037840 0.080573 -0.470 0.639
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137627 0.032695 0.198788 0.251294 0.062534 0.107542 -0.049082 0.169013
Kärnten 0.137627 1.000000 0.004013 0.197069 0.165700 -0.118577 0.154129 0.006617 0.317112
Niederösterreich 0.032695 0.004013 1.000000 0.287573 0.080923 0.210115 0.114606 0.044863 0.367433
Oberösterreich 0.198788 0.197069 0.287573 1.000000 0.296683 0.291397 0.108962 0.075616 0.126837
Salzburg 0.251294 0.165700 0.080923 0.296683 1.000000 0.150786 0.057078 0.090693 -0.010437
Steiermark 0.062534 -0.118577 0.210115 0.291397 0.150786 1.000000 0.101690 0.103965 -0.105019
Tirol 0.107542 0.154129 0.114606 0.108962 0.057078 0.101690 1.000000 0.163686 0.155160
Vorarlberg -0.049082 0.006617 0.044863 0.075616 0.090693 0.103965 0.163686 1.000000 0.033800
Wien 0.169013 0.317112 0.367433 0.126837 -0.010437 -0.105019 0.155160 0.033800 1.000000